/**
 * @(#)RetentFilterConfigServiceImpl.java 2017年7月4日
 * Copyright(C) 2017 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.service.impl;

import org.jsbd.boss.common.redis.RedisClient;
import org.jsbd.boss.dao.IRetentFilterDao;
import org.jsbd.boss.domian.channel.MarkDayTask;
import org.jsbd.boss.domian.channel.RetentFilter;
import org.jsbd.boss.domian.channel.RetentTaskVo;
import org.jsbd.boss.service.IRetentFilterService;
import org.jsbd.boss.util.CacheKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * TODO 请加入本类的说明
 *
 * @author <a href="mailto:xupengcheng@zhexinit.com" >徐鹏程</a>
 * @version 1.0.0
 */
@Service
public class RetentFilterServiceImpl implements IRetentFilterService {
    public static final Logger LOGGER = LoggerFactory.getLogger(RetentFilterServiceImpl.class);

    @Resource
    private IRetentFilterDao retentFilterDao;

    @Resource
    private RedisClient redisClient;

    @Override
    public List<RetentTaskVo> selectRetentTaskInfoList(RetentFilter filter) {
        return retentFilterDao.selectRetentTaskInfoList(filter);
    }

    @Override
    public List<MarkDayTask> selectRetentMarkDayTask(Integer day, String apk) {
        String key = CacheKey.RETENT_FILTER_TASK + day + apk;
        List<MarkDayTask> tasks = (List<MarkDayTask>) redisClient.get(key);
        if (tasks == null || tasks.size() > 0) {
            tasks = retentFilterDao.selectRetentMarkDayTask(day, apk);
            if (tasks != null && tasks.size() > 0) {
                redisClient.put(key, tasks, 300);
            }
        }

        if (tasks != null && tasks.size() > 0) {
            return tasks;
        }
        return null;
    }

}
